package org.dlx.common;

//快速排序
public class QuickSorter
{
    public static void sort(int[] arr, int left, int right){
        if(left >= right){
            return;
        }
        int i = left;
        int j = right;
        //可以随机化 把随机的index 和left值交换一下
        int key = arr[left];
        while(i < j) {
            //从右往前数 找到1个大于key的数
            while(i < j && key <= arr[j]) {
                j--;
            }
            arr[i] = arr[j];
            while(i < j && key >= arr[i]) {
               i++;
            }
            arr[j] = arr[i];
        }
        arr[i] = key;
        sort(arr, left, i - 1);
        sort(arr, i + 1, right);
    }
}
